package com.sky.controller.user;

import com.sky.dto.OrdersPaymentDTO;
import com.sky.dto.OrdersSubmitDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderPaymentVO;
import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 老杨
 * @version 1.0
 */
@RestController("userOrderController")
@RequestMapping("/user/order")
@Api(tags = "用户下单管理接口")
@Slf4j
public class OrderController {

    @Autowired
    OrderService orderService;

    @ApiOperation(value = "用户下单接口")
    @PostMapping("/submit")
    public Result<OrderSubmitVO> placeOrder(@RequestBody OrdersSubmitDTO ordersSubmitDTO){
        OrderSubmitVO orderSubmitVO = orderService.orderSubmit(ordersSubmitDTO);
        return Result.success(orderSubmitVO);
    }


    /**
     * 订单支付
     *
     * @param ordersPaymentDTO
     * @return
     */
    @PutMapping("/payment")
    @ApiOperation("订单支付")
    public Result<OrderPaymentVO> payment(@RequestBody OrdersPaymentDTO ordersPaymentDTO) throws Exception {
        //因为订单支付 暂时没法实现，使用伪支付
        orderService.payment2(ordersPaymentDTO);

//        log.info("订单支付：{}", ordersPaymentDTO);
//        OrderPaymentVO orderPaymentVO = orderService.payment(ordersPaymentDTO);
//        log.info("生成预支付交易单：{}", orderPaymentVO);
        return Result.success();
    }


    @ApiOperation(value = "查询历史订单")
    @GetMapping("/historyOrders")
    public Result<PageResult> historyOrders(int page,int pageSize,Integer status){
        log.info(page+" "+pageSize+" "+status);
        PageResult page1 = orderService.page(page, pageSize, status);
        return Result.success(page1);
    }

    @ApiOperation(value = "查询订单详情")
    @GetMapping("/orderDetail/{id}")
    public Result<OrderVO> orderDetail(@PathVariable Long id){
        OrderVO orderVO = orderService.orderDetail(id);
        return Result.success(orderVO);
    }


    @ApiOperation(value = "订单取消")
    @PutMapping("cancel/{id}")
    public Result cancelOrder(@PathVariable Long id){
        orderService.cancelOrder(id);
        return Result.success();
    }

    @ApiOperation(value = "再来一单")
    @PostMapping("/repetition/{id}")
    public Result repetitionOrder(@PathVariable Long id){
        orderService.repetitionOrder(id);
        return Result.success();
    }

    @ApiOperation(value = "催单功能接口")
    @GetMapping("/reminder/{id}")
    public Result reminder(@PathVariable Long id){
            orderService.reminder(id);
            return Result.success();
    }
}
